<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%
	request.setCharacterEncoding("UTF-8");
	String cp = request.getContextPath();
	int i=0;
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>관리자 리스트</title>
<style type="text/css">

body {
font-size: 9pt;
 }

</style>

<script type="text/javascript">

	function deleteCheck(){
		
		var f = document.myForm;
		var dlength;
		var productionNum;
		var count=0;

        dlength = window.document.myForm["delete[]"].length;
		
        for(i=0;i<=dlength;i++){

            if(window.document.myForm["delete[]"][i].checked){
            	productionNum =
            		window.document.myForm["delete[]"][i].value;
            	count++;
            }

   	 	}
        
        if(count>1){
        	alert("아직 중복 삭제는 안됩니다.");
        	return;
        }
        
        if(productionNum==null){
        	alert("삭제할 상품을 선택해 주세요.");
        	return;
        }
       
        f.action = "<%=cp%>/production/delete.action?productionNum=" + productionNum;
       
        f.submit();

	}
	
	function searchData(){
		
		var f = document.searchForm;
		
		f.action = "<%=cp%>/production/admin_list.action?searchKey=" + f.searchKey.value
				+"&searchValue=" + f.searchValue.value;
		
		f.submit();
		
	}
	
</script>

</head>
<body>

<center>
<br/>
<form action="" method="post" name="myForm">

<table width="800" >

	<tr>
		<td width="350" colspan="2" align="center">
			<h2>상품 목록</h2>
		</td>
		<td width="50">
			<input type="button" value=" 상품 등록 " class="btn1"
			onclick="javascript:location.href='<%=cp%>/production/write.action';">
		</td>
	</tr>
	
	<tr>
		<td width="80" align="right" colspan="3">
			<br/>
			totalDataCount : ${totalDataCount}, totalPage : ${totalPage}
		</td>
	</tr>
	
	<tr>
		<td colspan="3">
			<hr size="1">
		</td>
	</tr>
	
	<tr>
		<td width="80" align="center">
			Main Image
		</td>
		<td align="center">
			Content
		</td>
		<td align="center">
			option
		</td>
	</tr>
		
	<c:forEach var="dto" items="${lists}">
	<tr>
		<td colspan="3">
			<hr size="1">
		</td>
	</tr>
	<tr>
		<td width="80" align="center">
			<c:forEach var="imageDTO" items="${listImage}">
			<c:if test="${imageDTO.productionNum==dto.productionNum}">
			<img width="80" height="80" src="${imageURI}${imageDTO.saveFileName}"><br/>
			</c:if>
			</c:forEach>
		</td>
		<td>
			<font style="margin-left: 10pt">상품 이름 : <b>${dto.name}</b></font><br/>
			<font style="margin-left: 10pt">상품 정보 : <a href="<%=cp%>/production/article.action?productionNum=${dto.productionNum}&${params}">${dto.subject}</a></font><br/>
			<font style="margin-left: 10pt">상품 가격 : ${dto.price}</font><br/>
			<font style="margin-left: 10pt">등록 지역 : ${dto.productionLocal}</font><br/>
			<font style="margin-left: 10pt">상품 분류 : ${dto.productionCategory}</font>
		</td>
		<td align="center">
			<input type="checkbox" name="delete[]" value="${dto.productionNum}">
			<input type="button" value="삭제" onclick="deleteCheck();">
		</td>
	</tr>
	
	</c:forEach>
	<tr>
		<td colspan="3">
			<hr size="1">
		</td>
	</tr>
</table>

</form>

<br/>

<form name="searchForm" method="post" action="">
<table width="800">
	<tr>
		<c:if test="${totalDataCount != 0}">
		${pageIndexList}
		</c:if>
		<c:if test="${totalDataCount == 0}">
		등록된 게시물이 없습니다
		</c:if>
	</tr>

	<tr align="right">
		<td>
			<select name="searchKey">
				<option value="name">상품 이름</option>
				<option value="subject">상품 정보</option>
				<option value="productionLocal">등록 지역</option>
				<option value="productionCategory">상품 분류</option>
			</select>
			<input type="text" name="searchValue">
			<input type="button" value=" 검 색 " onclick="searchData();">
		</td>
	</tr>

</table>
</form>

</center>

</body>
</html>